package com.ruoyi.middleman.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.middleman.domain.AtbMiddleman;
import com.ruoyi.middleman.service.IAtbMiddlemanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 中介Controller
 * 
 * @author ruoyi
 * @date 2024-09-14
 */
@RestController
@RequestMapping("/middleman/middleman")
public class AtbMiddlemanController extends BaseController
{
    @Autowired
    private IAtbMiddlemanService atbMiddlemanService;

    /**
     * 查询中介列表
     */
    @PreAuthorize("@ss.hasPermi('middleman:middleman:list')")
    @GetMapping("/list")
    public TableDataInfo list(AtbMiddleman atbMiddleman)
    {
        startPage();
        List<AtbMiddleman> list = atbMiddlemanService.selectAtbMiddlemanList(atbMiddleman);
        return getDataTable(list);
    }

    /**
     * 导出中介列表
     */
    @PreAuthorize("@ss.hasPermi('middleman:middleman:export')")
    @Log(title = "中介", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AtbMiddleman atbMiddleman)
    {
        List<AtbMiddleman> list = atbMiddlemanService.selectAtbMiddlemanList(atbMiddleman);
        ExcelUtil<AtbMiddleman> util = new ExcelUtil<AtbMiddleman>(AtbMiddleman.class);
        util.exportExcel(response, list, "中介数据");
    }

    /**
     * 获取中介详细信息
     */
    @PreAuthorize("@ss.hasPermi('middleman:middleman:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(atbMiddlemanService.selectAtbMiddlemanById(id));
    }

    /**
     * 新增中介
     */
    @PreAuthorize("@ss.hasPermi('middleman:middleman:add')")
    @Log(title = "中介", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AtbMiddleman atbMiddleman)
    {
        return toAjax(atbMiddlemanService.insertAtbMiddleman(atbMiddleman));
    }

    /**
     * 修改中介
     */
    @PreAuthorize("@ss.hasPermi('middleman:middleman:edit')")
    @Log(title = "中介", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AtbMiddleman atbMiddleman)
    {
        return toAjax(atbMiddlemanService.updateAtbMiddleman(atbMiddleman));
    }

    /**
     * 删除中介
     */
    @PreAuthorize("@ss.hasPermi('middleman:middleman:remove')")
    @Log(title = "中介", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(atbMiddlemanService.deleteAtbMiddlemanByIds(ids));
    }
}
